/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.AdHocOrderingTypes;
import bpmn.Assignment;
import bpmn.BpmnPackage;
import bpmn.Expression;
import bpmn.GraphicalElement;
import bpmn.InputSet;
import bpmn.OutputSet;
import bpmn.ProcessType;
import bpmn.Property;
import bpmn.StatusType;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.ProcessImpl#getName <em>Name</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getProcessType <em>Process Type</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getStatus <em>Status</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getGraphicalElements <em>Graphical Elements</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getAssignments <em>Assignments</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getPerformers <em>Performers</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getInputSets <em>Input Sets</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getOutputSets <em>Output Sets</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getAdHoc <em>Ad Hoc</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getAdHocOrdering <em>Ad Hoc Ordering</em>}</li>
 *   <li>{@link bpmn.impl.ProcessImpl#getAdHocCompletionCondition <em>Ad Hoc Completion Condition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProcessImpl extends SupportingElementImpl implements bpmn.Process {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getProcessType() <em>Process Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcessType()
	 * @generated
	 * @ordered
	 */
	protected static final ProcessType PROCESS_TYPE_EDEFAULT = ProcessType.NONE;

	/**
	 * The cached value of the '{@link #getProcessType() <em>Process Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcessType()
	 * @generated
	 * @ordered
	 */
	protected ProcessType processType = PROCESS_TYPE_EDEFAULT;

	/**
	 * The default value of the '{@link #getStatus() <em>Status</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStatus()
	 * @generated
	 * @ordered
	 */
	protected static final StatusType STATUS_EDEFAULT = StatusType.NONE;

	/**
	 * The cached value of the '{@link #getStatus() <em>Status</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStatus()
	 * @generated
	 * @ordered
	 */
	protected StatusType status = STATUS_EDEFAULT;

	/**
	 * The cached value of the '{@link #getGraphicalElements() <em>Graphical Elements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGraphicalElements()
	 * @generated
	 * @ordered
	 */
	protected EList<GraphicalElement> graphicalElements;

	/**
	 * The cached value of the '{@link #getAssignments() <em>Assignments</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAssignments()
	 * @generated
	 * @ordered
	 */
	protected EList<Assignment> assignments;

	/**
	 * The cached value of the '{@link #getPerformers() <em>Performers</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPerformers()
	 * @generated
	 * @ordered
	 */
	protected EList<String> performers;

	/**
	 * The cached value of the '{@link #getProperties() <em>Properties</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProperties()
	 * @generated
	 * @ordered
	 */
	protected EList<Property> properties;

	/**
	 * The cached value of the '{@link #getInputSets() <em>Input Sets</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputSets()
	 * @generated
	 * @ordered
	 */
	protected EList<InputSet> inputSets;

	/**
	 * The cached value of the '{@link #getOutputSets() <em>Output Sets</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutputSets()
	 * @generated
	 * @ordered
	 */
	protected EList<OutputSet> outputSets;

	/**
	 * The default value of the '{@link #getAdHoc() <em>Ad Hoc</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHoc()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean AD_HOC_EDEFAULT = Boolean.FALSE;

	/**
	 * The cached value of the '{@link #getAdHoc() <em>Ad Hoc</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHoc()
	 * @generated
	 * @ordered
	 */
	protected Boolean adHoc = AD_HOC_EDEFAULT;

	/**
	 * The default value of the '{@link #getAdHocOrdering() <em>Ad Hoc Ordering</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocOrdering()
	 * @generated
	 * @ordered
	 */
	protected static final AdHocOrderingTypes AD_HOC_ORDERING_EDEFAULT = AdHocOrderingTypes.SEQUENTIAL;

	/**
	 * The cached value of the '{@link #getAdHocOrdering() <em>Ad Hoc Ordering</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocOrdering()
	 * @generated
	 * @ordered
	 */
	protected AdHocOrderingTypes adHocOrdering = AD_HOC_ORDERING_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAdHocCompletionCondition() <em>Ad Hoc Completion Condition</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocCompletionCondition()
	 * @generated
	 * @ordered
	 */
	protected Expression adHocCompletionCondition;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProcessImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.PROCESS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ProcessType getProcessType() {
		return processType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProcessType(ProcessType newProcessType) {
		ProcessType oldProcessType = processType;
		processType = newProcessType == null ? PROCESS_TYPE_EDEFAULT : newProcessType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__PROCESS_TYPE, oldProcessType, processType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StatusType getStatus() {
		return status;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStatus(StatusType newStatus) {
		StatusType oldStatus = status;
		status = newStatus == null ? STATUS_EDEFAULT : newStatus;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__STATUS, oldStatus, status));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GraphicalElement> getGraphicalElements() {
		if (graphicalElements == null) {
			graphicalElements = new EObjectContainmentEList<GraphicalElement>(GraphicalElement.class, this, BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS);
		}
		return graphicalElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Assignment> getAssignments() {
		if (assignments == null) {
			assignments = new EObjectResolvingEList<Assignment>(Assignment.class, this, BpmnPackage.PROCESS__ASSIGNMENTS);
		}
		return assignments;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<String> getPerformers() {
		if (performers == null) {
			performers = new EDataTypeUniqueEList<String>(String.class, this, BpmnPackage.PROCESS__PERFORMERS);
		}
		return performers;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Property> getProperties() {
		if (properties == null) {
			properties = new EObjectContainmentEList<Property>(Property.class, this, BpmnPackage.PROCESS__PROPERTIES);
		}
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<InputSet> getInputSets() {
		if (inputSets == null) {
			inputSets = new EObjectResolvingEList<InputSet>(InputSet.class, this, BpmnPackage.PROCESS__INPUT_SETS);
		}
		return inputSets;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputSet> getOutputSets() {
		if (outputSets == null) {
			outputSets = new EObjectResolvingEList<OutputSet>(OutputSet.class, this, BpmnPackage.PROCESS__OUTPUT_SETS);
		}
		return outputSets;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Boolean getAdHoc() {
		return adHoc;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHoc(Boolean newAdHoc) {
		Boolean oldAdHoc = adHoc;
		adHoc = newAdHoc;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__AD_HOC, oldAdHoc, adHoc));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public AdHocOrderingTypes getAdHocOrdering() {
		return adHocOrdering;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHocOrdering(AdHocOrderingTypes newAdHocOrdering) {
		AdHocOrderingTypes oldAdHocOrdering = adHocOrdering;
		adHocOrdering = newAdHocOrdering == null ? AD_HOC_ORDERING_EDEFAULT : newAdHocOrdering;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__AD_HOC_ORDERING, oldAdHocOrdering, adHocOrdering));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Expression getAdHocCompletionCondition() {
		if (adHocCompletionCondition != null && adHocCompletionCondition.eIsProxy()) {
			InternalEObject oldAdHocCompletionCondition = (InternalEObject)adHocCompletionCondition;
			adHocCompletionCondition = (Expression)eResolveProxy(oldAdHocCompletionCondition);
			if (adHocCompletionCondition != oldAdHocCompletionCondition) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION, oldAdHocCompletionCondition, adHocCompletionCondition));
			}
		}
		return adHocCompletionCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Expression basicGetAdHocCompletionCondition() {
		return adHocCompletionCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHocCompletionCondition(Expression newAdHocCompletionCondition) {
		Expression oldAdHocCompletionCondition = adHocCompletionCondition;
		adHocCompletionCondition = newAdHocCompletionCondition;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION, oldAdHocCompletionCondition, adHocCompletionCondition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS:
				return ((InternalEList<?>)getGraphicalElements()).basicRemove(otherEnd, msgs);
			case BpmnPackage.PROCESS__PROPERTIES:
				return ((InternalEList<?>)getProperties()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.PROCESS__NAME:
				return getName();
			case BpmnPackage.PROCESS__PROCESS_TYPE:
				return getProcessType();
			case BpmnPackage.PROCESS__STATUS:
				return getStatus();
			case BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS:
				return getGraphicalElements();
			case BpmnPackage.PROCESS__ASSIGNMENTS:
				return getAssignments();
			case BpmnPackage.PROCESS__PERFORMERS:
				return getPerformers();
			case BpmnPackage.PROCESS__PROPERTIES:
				return getProperties();
			case BpmnPackage.PROCESS__INPUT_SETS:
				return getInputSets();
			case BpmnPackage.PROCESS__OUTPUT_SETS:
				return getOutputSets();
			case BpmnPackage.PROCESS__AD_HOC:
				return getAdHoc();
			case BpmnPackage.PROCESS__AD_HOC_ORDERING:
				return getAdHocOrdering();
			case BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION:
				if (resolve) return getAdHocCompletionCondition();
				return basicGetAdHocCompletionCondition();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.PROCESS__NAME:
				setName((String)newValue);
				return;
			case BpmnPackage.PROCESS__PROCESS_TYPE:
				setProcessType((ProcessType)newValue);
				return;
			case BpmnPackage.PROCESS__STATUS:
				setStatus((StatusType)newValue);
				return;
			case BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				getGraphicalElements().addAll((Collection<? extends GraphicalElement>)newValue);
				return;
			case BpmnPackage.PROCESS__ASSIGNMENTS:
				getAssignments().clear();
				getAssignments().addAll((Collection<? extends Assignment>)newValue);
				return;
			case BpmnPackage.PROCESS__PERFORMERS:
				getPerformers().clear();
				getPerformers().addAll((Collection<? extends String>)newValue);
				return;
			case BpmnPackage.PROCESS__PROPERTIES:
				getProperties().clear();
				getProperties().addAll((Collection<? extends Property>)newValue);
				return;
			case BpmnPackage.PROCESS__INPUT_SETS:
				getInputSets().clear();
				getInputSets().addAll((Collection<? extends InputSet>)newValue);
				return;
			case BpmnPackage.PROCESS__OUTPUT_SETS:
				getOutputSets().clear();
				getOutputSets().addAll((Collection<? extends OutputSet>)newValue);
				return;
			case BpmnPackage.PROCESS__AD_HOC:
				setAdHoc((Boolean)newValue);
				return;
			case BpmnPackage.PROCESS__AD_HOC_ORDERING:
				setAdHocOrdering((AdHocOrderingTypes)newValue);
				return;
			case BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION:
				setAdHocCompletionCondition((Expression)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.PROCESS__NAME:
				setName(NAME_EDEFAULT);
				return;
			case BpmnPackage.PROCESS__PROCESS_TYPE:
				setProcessType(PROCESS_TYPE_EDEFAULT);
				return;
			case BpmnPackage.PROCESS__STATUS:
				setStatus(STATUS_EDEFAULT);
				return;
			case BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				return;
			case BpmnPackage.PROCESS__ASSIGNMENTS:
				getAssignments().clear();
				return;
			case BpmnPackage.PROCESS__PERFORMERS:
				getPerformers().clear();
				return;
			case BpmnPackage.PROCESS__PROPERTIES:
				getProperties().clear();
				return;
			case BpmnPackage.PROCESS__INPUT_SETS:
				getInputSets().clear();
				return;
			case BpmnPackage.PROCESS__OUTPUT_SETS:
				getOutputSets().clear();
				return;
			case BpmnPackage.PROCESS__AD_HOC:
				setAdHoc(AD_HOC_EDEFAULT);
				return;
			case BpmnPackage.PROCESS__AD_HOC_ORDERING:
				setAdHocOrdering(AD_HOC_ORDERING_EDEFAULT);
				return;
			case BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION:
				setAdHocCompletionCondition((Expression)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.PROCESS__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case BpmnPackage.PROCESS__PROCESS_TYPE:
				return processType != PROCESS_TYPE_EDEFAULT;
			case BpmnPackage.PROCESS__STATUS:
				return status != STATUS_EDEFAULT;
			case BpmnPackage.PROCESS__GRAPHICAL_ELEMENTS:
				return graphicalElements != null && !graphicalElements.isEmpty();
			case BpmnPackage.PROCESS__ASSIGNMENTS:
				return assignments != null && !assignments.isEmpty();
			case BpmnPackage.PROCESS__PERFORMERS:
				return performers != null && !performers.isEmpty();
			case BpmnPackage.PROCESS__PROPERTIES:
				return properties != null && !properties.isEmpty();
			case BpmnPackage.PROCESS__INPUT_SETS:
				return inputSets != null && !inputSets.isEmpty();
			case BpmnPackage.PROCESS__OUTPUT_SETS:
				return outputSets != null && !outputSets.isEmpty();
			case BpmnPackage.PROCESS__AD_HOC:
				return AD_HOC_EDEFAULT == null ? adHoc != null : !AD_HOC_EDEFAULT.equals(adHoc);
			case BpmnPackage.PROCESS__AD_HOC_ORDERING:
				return adHocOrdering != AD_HOC_ORDERING_EDEFAULT;
			case BpmnPackage.PROCESS__AD_HOC_COMPLETION_CONDITION:
				return adHocCompletionCondition != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (Name: ");
		result.append(name);
		result.append(", ProcessType: ");
		result.append(processType);
		result.append(", Status: ");
		result.append(status);
		result.append(", Performers: ");
		result.append(performers);
		result.append(", AdHoc: ");
		result.append(adHoc);
		result.append(", AdHocOrdering: ");
		result.append(adHocOrdering);
		result.append(')');
		return result.toString();
	}

} //ProcessImpl
